const examService = require("../services/examService");


const exam={
    /**
     * 默认题库试题详情根据题目Id查询题目选项
     * @returns 
     */
    getQuestionOptions:async(req,res,next)=>{
        const {tid}= req.query; 
        const result=await examService.getQuestionOptions(tid);
        return res.json(result);
    },
    /**
     * 查询默认题库试题的试题列表的题目详情
     */
    getQuestionDetails:async(req,res,next)=>{
        const {tid}= req.query; 
        const result=await examService.getQuestionDetails(tid);
        return res.json(result);
    },
    /**
     * 获取当前页面满足勾选的复选框的默认题库试题的试题列表
     * @returns 
     */
    queryAllQuestionChecks:async(req,res,next)=>{
        const {page,limit,key,IsPusblish,IsBan}= req.query;  
        const result=await examService.queryAllQuestionChecks(page,limit,key,IsPusblish,IsBan);
        return res.json(result);
       },
      /**
     * 默认题库题目的禁用与恢复 传值1/0
     */
      TopicIsBan:async(req,res,next)=>{
        const {id,IsBan}=req.body;
        const result=await examService.TopicIsBan(id,IsBan);
        return res.json(result);
    },
   
      /**
     * 默认题库题目的发布
     */
      delQUestion:async(req,res,next)=>{
        const {id}=req.body;
        const result=await examService.delQUestion(id);
        return res.json(result);
    },
    /**
     * 默认题库题目的发布
     */
    TopicIsPublish:async(req,res,next)=>{
        const {qid,IsPublish}=req.body;
        const result=await examService.TopicIsPublish(qid,IsPublish);
        return res.json(result);
    },
     /**
     * 默认题库试题的试题列表
     * @param {*} page 
     * @param {*} limit 
     * @param {*} key 模糊查询 题干
     * @returns 
     */
     queryAllQuestion:async(req,res,next)=>{
         const {page,limit,key,params}= req.query;   
         const result=await examService.queryAllQuestion(page,limit,key,params);
         return res.json(result);
        },
    /**
     * 新增默认题库题目
     */
    addTopic:async(req,res,next)=>{
        const user=res.user;
        const {content,typeX,lv,label, options,analysis}=req.body;
        const result=await examService.addTopic(user.UID,content,typeX,lv,label, options,analysis);
        return res.json(result);
    },

    /**
     * 新增题库
     */
    addQuestion:async(req,res,next)=>{
        const {QBName,QBCount,QBParent,QBLabel, QBLv,QBlsPublish,QBlsBan,QBExplain,QBDesc}=req.body;
        const result=await examService.addQuestion(QBName,QBCount,QBParent,QBLabel, QBLv,QBlsPublish,QBlsBan,QBExplain,QBDesc);
        return res.json(result);
    },
    /**
     * 修改题库是否发布
     * IsPunblish 1为当前已发布 0为未发布
     */
    editPublish:async(req,res,next)=>{
        const {id,IsPublish}=req.body;
        const result=await examService.editPublish(id,IsPublish);
        return res.json(result);
    },

   /**
    * 修改是否禁用
    * 1为当前禁用 /0为当前启用
    */
    editIsBan:async(req,res,next)=>{
        const {id,IsBan}=req.body;
        const result=await examService.editIsBan(id,IsBan);
        return res.json(result);
    },
    /**
     * 根据题库id删除题库
     */
     delQuestionBank:async(req,res,next)=>{
        const {id}=req.body;
        const result=await examService.delQuestionBank(id);
        return res.json(result)
     },
    /**
     * 获取当前页面的题库数据
     * @returns 
     */
    getQuestionBanks:async (req,res,next)=>{
           const {page,limit,key}=req.query;
           const result=await examService.getQuestionBanks(page,limit,key);
           return res.json(result)
    },
    /**
     * 获取默认题库的数量
     */
    getQuestionBankCount:async(req,res,next)=>{
        const result=await examService.getQuestionBankCount();
        return res.json(result)
    }
};
 
  

module.exports=exam